package controller;

import java.sql.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;

import model.PositiveTransaction;
import model.Transaction;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

import daoImpl.TransactionDaoImpl;


public class DrawGraph implements Observer{
	
	public DrawGraph( List<Transaction> transactions ) {
		TimeSeries series = new TimeSeries( "Transactions" );
		Map<Date, Double> values = new HashMap<Date, Double>();
		transactions.add( new PositiveTransaction( 300, "2e", (System.currentTimeMillis()-370000000) ) );
		for( Transaction tran : transactions ){
			 series.addOrUpdate( new Day(tran.getDate()), tran.getAmount());
		}
		// x = age y=weigth
//		series.add( 20.0, 20.0 );
//		series.add( 40.0, 25.0 );
//		series.add( 55.0, 50.0 );
//		series.add( 70.0, 65.0 );
		TimeSeriesCollection xyDataset = new TimeSeriesCollection( series );
		JFreeChart chart = ChartFactory.createXYLineChart( "XYLine Chart using JFreeChart", "Date", "Amount", xyDataset,
				PlotOrientation.VERTICAL, true, true, false );
		
		ChartFrame frame1 = new ChartFrame( "XYLine Chart", chart );
		frame1.setVisible( true );
		frame1.setSize( 500, 500 );
		
	}
	
	
	public static void main( String[] args ) {
		List<Transaction> transactions = new ArrayList<Transaction>();
		transactions.add( new PositiveTransaction( 200, "1e" ) );
		
		transactions.add( new PositiveTransaction( 300, "2e" ) );
		new DrawGraph(transactions  );
		
	}


	@Override
	public void update( Observable obs, Object arg1 ) {
		if(obs instanceof TransactionDaoImpl){
			TransactionDaoImpl dao = (TransactionDaoImpl) obs;
			
		}
		
	}
}